package servlet.user;


import entity.User;
import service.Impl.UserServiceImpl;
import service.UserService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/user/create")
public class UserRegisterServlet extends HttpServlet {
    private UserService userService=new UserServiceImpl();

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String userName = request.getParameter("userName");
        String password = request.getParameter("password");
        String email = request.getParameter("email");
        String age = request.getParameter("age");
        String sex = request.getParameter("sex");
        String telephone = request.getParameter("telephone");
        String address = request.getParameter("address");
        String pic = request.getParameter("pic");
        String state = request.getParameter("state");
        // 其他字段获取和设置省略
        User user = new User();
        user.setUserName(userName);
        user.setPassword(password);
        user.setAge(Integer.parseInt(age));
        user.setSex(sex);
        user.setTelephone(telephone);
        user.setEmail(email);
        user.setAddress(address);
        user.setPic(pic);
        user.setState(Integer.parseInt(state));
        // 设置其他属性
        userService.addUser(user);
        response.setContentType("application/json");
        response.getWriter().write("{ \"message\": \"注册成功，请去登录！\" }");
    }
}